import requests
import time
import random
from wasmer import engine, Store, Module, Instance
import wasmer_compiler_cranelift

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
}
cookies = {
    "sessionid": "go27jyi6r52uxsdytuuju8waihdf6a4w",
    "qpfccr": "true",
    "no-alert3": "true",
    "tk": "-1255646144774564450"
}
url = "https://match.yuanrenxue.cn/api/match/15"

def get_mkey1(t1,t2):
    # 加载 WASM 文件   
    # wat2wasm ./test_a.wat -o ./module.wasm
    with open(r'E:\Python\vscode\Crawlers\yuanrenxue\no15\module.wasm', 'rb') as f:
        wasm_bytes = f.read()
    # 创建实例
    store = Store(engine.JIT(wasmer_compiler_cranelift.Compiler))
    module = Module(store, wasm_bytes)
    instance = Instance(module)

    # 调用 encode 函数
    result = instance.exports.encode(t1, t2)
    return str(result) + '|' + str(t1) + '|' + str(t2)

num_list = []
for i in range(1,6):
    t1 = int(time.time())//2;
    t2 = int(time.time())//2 - random.randint(1, 50);
    params = {
        "m": get_mkey1(t1,t2),
        "page": i
    }
    response = requests.get(url, headers=headers, cookies=cookies, params=params)
    datas = response.json()['data']
    for i in datas:
        num_list.append(i['value'])

print(sum(num_list))